# Context switch
#
#   void swtch(struct context **old, struct context *new);
# 
# Save the current registers on the stack, creating
# a struct context, and save its address in *old.
# Switch stacks to new and pop previously-saved registers.

.globl swtch
swtch:
	# TODO: your code here
	# DEBUG
	# Q: Whether to push trapret addr, and is the above a trapframe?
	# pushl $(forkret)
	# Save old callee-saved registers
	movl 0x4(%esp), %eax
	pushl %ebp
	pushl %ebx
	pushl %esi
	pushl %edi
	movl %esp, (%eax)
	# Switch stacks
	movl 0x18(%esp), %esp
	# Load new callee-saved registers
	popl %edi
	popl %esi
	popl %ebx
	popl %ebp
	ret
